﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.User;
using System.Collections;
using Direct.IDAL.User.Jurisdiction;
using DirectSell.BLL.EFBase;

namespace DirectSell.BLL.User.Jurisdiction
{
    /// <summary>
    /// 会员升级业务逻辑层
    /// </summary>
    public class UserUpgradeService:UserService
    {
        #region 初始化数据
        /// <summary>
        /// 日志记录文件夹
        /// </summary>
        protected override string LogFile => "会员升级";
        /// <summary>
        /// 会员升级数据接口
        /// </summary>
        protected IUserUpgradeRepository _userUpgrade { get; set; }

        public UserUpgradeService(IUserUpgradeRepository userUpgrade)
        {
            this._userUpgrade = userUpgrade;
        }

        #endregion

        /// <summary>
        /// 会员升级操作
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected async override Task<UserRespCode> OperationAsync<T>(T param)
        {
            var model = param as UserUpGradeReq;

            if (model == null)
            {
                return UserRespCode.传入参数不正确;
            }

            await LogAsync(model);

            Hashtable hsTable = new Hashtable();

            if( ! await _userUpgrade.IsRepeat(model))
            {
                return UserRespCode.重复提交;
            }

            _userUpgrade.UpApply(model, ref hsTable);

            if (!_userUpgrade.CommitDapperTranLock(hsTable))
            {
                return UserRespCode.失败;
            }

            return UserRespCode.成功;

        }
      }
    }
